package com.daz.teacher.lookScores.server.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daz.teacher.lookScores.dao.ILookScoresDao;
import com.daz.teacher.lookScores.pojo.StudentCreditPojo;
import com.daz.teacher.lookScores.pojo.StudentScoresPojo;
import com.daz.teacher.lookScores.server.ILookScoresService;
@Service
public class LookScoresServiceImpl implements ILookScoresService{
	@Autowired
	private ILookScoresDao lookScoresDao;
	public StudentCreditPojo searchStudentScores(Map<String, Object> map)throws Exception{
		StudentCreditPojo studentCreditPojo = new StudentCreditPojo();
		String studentName="";
		int totalCredit=0;  //总学分
		int totalHourse=0;  //总学时
		int totalGetCredit=0; //实获学分
		String gradePoint=""; //绩点
		int totalScore=0; //总成绩
		List<StudentScoresPojo> list = lookScoresDao.searchStudentScores(map);
		if(list != null && list.size()>0){
			for(int i = 0; i < list.size(); i++){
				StudentScoresPojo scores = list.get(i);
				totalCredit += Integer.parseInt(scores.getCredit());
				totalHourse += Integer.parseInt(scores.getHourse());
				totalScore += Integer.parseInt(scores.getScores());
				studentName = scores.getStudentName();
				if(scores.getScores() != null && Integer.parseInt(scores.getScores())>=60){
					totalGetCredit += Integer.parseInt(scores.getCredit());
				}
			}
			studentCreditPojo.setAvgScore((totalScore/list.size())+"");
			studentCreditPojo.setTotalCredit(totalCredit+"");
			studentCreditPojo.setTotalGetCredit(totalGetCredit+"");
			studentCreditPojo.setTotalHourse(totalHourse+"");
			studentCreditPojo.setGradePoint(gradePoint);
			studentCreditPojo.setStudentScores(list);
			studentCreditPojo.setStudentName(studentName);			
		}
		return studentCreditPojo;
		
	}

}
